home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / oleo_src.lha / src / panic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-27  |  2.7 KB  |  127 lines

  1. /*    Copyright (C) 1990 Free Software Foundation, Inc.
  2.  
  3. This file is part of Oleo, the GNU Spreadsheet.
  4.  
  5. Oleo is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 1, or (at your option)
  8. any later version.
  9.  
  10. Oleo is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with Oleo; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #undef NULL
  20. #include <stdio.h>
  21. #include "funcdef.h"
  22. #include "sysdef.h"
  23.  
  24. #include "global.h"
  25.  
  26. extern char **environ;
  27.  
  28. extern int dup EXT1(int);
  29. extern int close EXT1(int);
  30. extern void *sbrk EXT1(size_t);
  31. extern void *brk EXT1(void *);
  32.  
  33. void
  34. panic_write_file FUN2(FILE *,fp, struct rng *,rng)
  35. {
  36. #ifndef AMIGA
  37.     int fd;
  38.     void *datend;
  39.     void *datstart;
  40.     unsigned long cnt;
  41.  
  42.     if(rng) {
  43.         error_msg("Can't write partial panic-save files");
  44.         return;
  45.     }
  46.     fd=dup(fileno(fp));
  47.     if(fd<0) {
  48.         error_msg("Couldn't dup save file");
  49.         return;
  50.     }
  51.     datstart= (void *)(&environ+sizeof(char **));
  52.     datend=sbrk(0);
  53.     if(datend==(char *)-1) {
  54.         error_msg("Couldn't sbrk(0)!");
  55.         close(fd);
  56.         return;
  57.     }
  58.  
  59.     cnt=(char *)datend-(char *)datstart;
  60.     if(write(fd,&cnt,sizeof(cnt))!=sizeof(cnt)) {
  61.         error_msg("Couldn't write %lu (%d bytes) to save file",cnt,sizeof(cnt));
  62.         close(fd);
  63.         return;
  64.     }
  65.     if(write(fd,datstart,cnt)!=cnt) {
  66.         error_msg("Couldn't write %lu bytes to save file",cnt);
  67.         close(fd);
  68.         return;
  69.     }
  70.     if(close(fd)<0) {
  71.         error_msg("Couldn't close save file");
  72.         return;
  73.     }
  74. #endif
  75. }
  76.  
  77. void
  78. panic_read_file FUN2(FILE *,fp, int, ismerge)
  79. {
  80. #ifndef AMIGA
  81.     int fd;
  82.     unsigned long cnt;
  83.     void *datstart;
  84.  
  85.     if(ismerge) {
  86.         error_msg("Can't merge panic-save files");
  87.         return;
  88.     }
  89.     if((fd=dup(fileno(fp)))<0) {
  90.         error_msg("Couldn't dup save file");
  91.         return;
  92.     }
  93.     if(read(fd,(void *)&cnt,sizeof(cnt))!=sizeof(cnt)) {
  94.         error_msg("Couldn't read data_size (%d bytes) from save file",sizeof(cnt));
  95.         close(fd);
  96.         return;
  97.     }
  98.     datstart= (void *)(&environ+sizeof(char **));
  99.     if(brk((char *)datstart+cnt)==(void *)-1) {
  100.         error_msg("Couldn't allocate %lu bytes of memory",cnt);
  101.         close(fd);
  102.         return;
  103.     }
  104.     if(read(fd,datstart,cnt)!=cnt) {
  105.         error_msg("Couldn't read in %lu bytes of data",cnt);
  106.         close(fd);
  107.         return;
  108.     }
  109.     if(close(fd)<0)
  110.         error_msg("Couldn't close save file");
  111.     recenter_all_win();
  112. #endif
  113. }
  114.  
  115. int
  116. panic_set_options FUN2(int,set_opt, char *,option)
  117. {
  118.     return -1;
  119. }
  120.  
  121.  
  122. void
  123. panic_show_options FUN0()
  124. {
  125.     text_line("File format:  panic save   (quick-n-dirty data-segment dump)");
  126. }
  127.